package Io;

import java.io.*;

//DataInputStream和DataOutputStream
//注意：写的顺序要和读的顺序一样，否则会报错
public class Test9 {
    public static void main(String[] args) {
//        writeData();
        readData();
    }

    public static void  writeData(){
        try {
            DataOutputStream out = new DataOutputStream(new FileOutputStream("D:\\aa\\a\\b\\tt1.txt"));
            out.writeInt(1);
            out.writeChar('a');
            //写字符串
            out.writeUTF("我是顾新宇");
            out.close();
        } catch (Exception e) {
            e.printStackTrace();
        }

    }

    public static void readData(){
        try {
            DataInputStream in = new DataInputStream(new FileInputStream("D:\\aa\\a\\b\\tt1.txt"));
            int i = in.readInt();
            int c = in.readChar();
            //读字符串
            String s = in.readUTF();
            System.out.println(c+"\t"+i+"\t"+s);
            in.close();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
